<template>
	<view >
		<template v-if="list.length>0">
			<block v-for="(item,index) in list" :key="index">
				<index-list :item="item" :index="index"></index-list>
			</block>
			<loadMore :loadtext="loadtext"></loadMore>
		</template>
		<template v-if="list.length<1 && issearch">
			<noThing></noThing> 
		</template>
		
	</view>
</template>

<script>
	import indexList from '../../components/index/index-list.vue';
	import noThing from '../../components/no-thing/no-thing.vue'
	import loadMore from '../../components/common/load-more.vue'
	export default {
		data(){ 
			return {
				issearch:false,
				loadtext:"上拉加载更多",
				list: [],
				searchtext:""
			}
		},
		components:{
			
			indexList,
			noThing,
			loadMore
		},
		methods:{
			// 请求服务器获取数据
			getdata(){
					uni.showLoading()
				setTimeout(()=>{
					let arr = [
						{
							userpic: "../../static/demo/userpic/11.jpg",
							username: "撸大师",
							isguanzhu: true,
							title: "动态标题",
							type: "video", //img : 图文   video: 视频
							titlepic: "",
							infonum: {
								index: 2, //0:没有关注  1：赞  2：踩
								dingnum: 11,
								cainum: 2
							},
							commentnum: 10,
							sharenum: 66
						},
						{
							userpic: "../../static/demo/userpic/11.jpg",
							username: "撸大师",
							isguanzhu: false,
							title: "动态标题",
							type: "img", //img : 图文   video: 视频
							titlepic: "",
							infonum: {
								index: 0, //0:没有关注  1：赞  2：踩
								dingnum: 11,
								cainum: 2
							},
							commentnum: 10,
							sharenum: 66
						},
						{
							userpic: "../../static/demo/userpic/11.jpg",
							username: "撸大师",
							isguanzhu: false,
							title: "动态标题",
							type: "img", //img : 图文   video: 视频
							titlepic: "",
							infonum: {
								index: 0, //0:没有关注  1：赞  2：踩
								dingnum: 11,
								cainum: 2
							},
							commentnum: 10,
							sharenum: 66
						},
						{
							userpic: "../../static/demo/userpic/11.jpg",
							username: "撸大师",
							isguanzhu: false,
							title: "动态标题",
							type: "img", //img : 图文   video: 视频
							titlepic: "",
							infonum: {
								index: 0, //0:没有关注  1：赞  2：踩
								dingnum: 11,
								cainum: 2
							},
							commentnum: 10,
							sharenum: 66
						}
					];
					this.list = arr
					uni.hideLoading()
					this.issearch = true
				},1000)
				
				
				
			},
			// 上拉加载更多
			loadMore(){
						if(this.loadtext !== '上拉加载更多'){return ;}
						this.loadtext = '加载中'
						setTimeout(() => {
							let obj = {
										userpic: "../../static/demo/userpic/11.jpg",
										username: "撸大师",
										isguanzhu: true,
										title: "动态标题",
										type: "video", //img : 图文   video: 视频
										titlepic: "",
										infonum: {
											index: 2, //0:没有关注  1：赞  2：踩
											dingnum: 11,
											cainum: 2
										},
										commentnum: 10,
										sharenum: 66
									}
							this.list.push(obj)
							this.loadtext = '上拉加载更多'
						}, 1000);
			},
		},
		// 监听下拉刷新
		onPullDownRefresh(){
			this.getdata();
			uni.stopPullDownRefresh()
		},
		// 监听页面触底事件
		onReachBottom(){
			console.log('触底了')
			this.loadMore()
		},
		// 监听原生标题栏导航点击事件
		onNavigationBarButtonTap(e){
			console.log(JSON.stringify(e))
			if(e.index === 0){
				uni.navigateBack({
					delta:1
				})
			}
		},
		// 监听搜索框文本变化
		// 监听搜索框文本变化
			onNavigationBarSearchInputChanged(e){
				console.log("监听搜索框文本变化"+JSON.stringify(e))
				console.log(e.text)
				this.searchtext = e.text
			},
			// 监听点击搜索按钮事件
			onNavigationBarSearchInputConfirmed(e){
				console.log("监听点击搜索按钮事件"+JSON.stringify(e))
				console.log(e.text)
				if(e.text){
					this.getdata()
					uni.hideKeyboard()
				}
		}
	}
</script>

<style>
</style>
